package com.wanli.agent.homepage.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.agent.R;
import com.wanli.agent.bean.TransferAgentNewBean;
import com.wanli.agent.homepage.MachinesDetailsActivity;
import com.wanli.agent.homepage.TransferMachinesListActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 服务商列表
 */
public class TransferAgentListAdapter extends RecyclerView.Adapter<TransferAgentListAdapter.ViewHolder> {

    private List<TransferAgentNewBean.DataBean> listsBeans;
    private Context context;
    private String type;

    public TransferAgentListAdapter(List<TransferAgentNewBean.DataBean> listsBeans, String type) {
        this.listsBeans = listsBeans;
        this.type = type;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_transfer_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TransferAgentNewBean.DataBean dataBean = listsBeans.get(position);
        holder.tvNumber.setText(dataBean.getTotal_count() + "");
        holder.tvName.setText(dataBean.getName());
        holder.tvLook1.setOnClickListener(v -> {
            Intent intent = new Intent(context, MachinesDetailsActivity.class);
            intent.putExtra("type", type);
            intent.putExtra("child_agent_id", dataBean.getId() + "");
            intent.putExtra("agent_name", dataBean.getName());
            context.startActivity(intent);
        });
        holder.tvLook2.setOnClickListener(v -> {
            Intent intent = new Intent(context, TransferMachinesListActivity.class);
            intent.putExtra("type", type);
            intent.putExtra("bind_agent_id", dataBean.getId() + "");
            intent.putExtra("agent_name", dataBean.getName());
            intent.putExtra("status", "3");
            context.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_number)
        TextView tvNumber;
        @BindView(R.id.tv_look1)
        TextView tvLook1;
        @BindView(R.id.tv_look2)
        TextView tvLook2;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
